package com.example.nftapp;

import android.net.Uri;
import android.os.Bundle;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.nftapp.wdg.CustomVideoView;

public class VideoPlayerActivity extends AppCompatActivity {

    private CustomVideoView cvv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_video_player);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        // 找到CustomVideoView
        cvv = findViewById(R.id.cvv);
        // 给CustomVideoView设置视频资源
        Uri videoUri = Uri.parse("android.resource://" + getPackageName() + "/raw/" + R.raw.big_buck_bunny);
        cvv.setVideoUri(videoUri);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (cvv != null) {
            cvv.suspend();
            cvv = null;
        }
    }

}